// 给定一个字符串,以及一个字符集合,判断最短的包含字符集合的子串!!

#include <bits/stdc++.h>

using namespace std;

class comp1 {
    public:
        bool operator() (string& str1, string& str2) {
            return str1.length() < str2.length();
        }
};

class Solution3 {
    public:
        static string shortest_substr(string& str, string& char_set) {
            typedef pair<int, int> substr_idx;
            vector<substr_idx> substr_vecs;
            map<char, int> char_set_map;
            int first, end;
            first = end = 0;
            for (auto ch:char_set) {
                char_set_map[ch] = 0;
            }
            bool exist_char;
            for (;end < str.length(); ++end) {
                exist_char =true;
                if (char_set_map.find(str[end]) != char_set_map.end()) {
                    char_set_map[str[end]]++;
                }
                for (auto it:char_set_map) {
                    if (it.second == 0) {
                        exist_char  =false;
                        break;
                    }
                }
                if (exist_char) {
                    while (exist_char) {
                        substr_vecs.push_back(substr_idx(first, end));
                        if (char_set_map.find(str[first]) != char_set_map.end()) {
                            char_set_map[str[first]]--;
                        }
                        first++;
                        for (auto it:char_set_map) {
                            if (it.second == 0) {
                                exist_char  =false;
                                break;
                            }
                        }
                    }
                    
                }
            }
            sort(substr_vecs.begin(), substr_vecs.end(), [](substr_idx& a, substr_idx& b) {
                return (a.second-a.first) < (b.second-b.first);
            });
            return str.substr(substr_vecs[0].first, substr_vecs[0].second-substr_vecs[0].first+1);
        }
};

class Solution1 {
    public:
        static string shortest_substr(string& str, string& char_set) {
            // 暴力方式
            vector<string> str_vecs;
            bool include_char = false;
            for (int i = 0; i < str.length(); ++i) {
                for (int j = i; j < str.length(); ++j) {
                    for (auto ch: char_set) {
                        include_char = false;
                        for (int k = i; k <= j; ++k) {
                            if (ch == str[k]) {
                                include_char = true;
                                break;
                            }
                        }
                        if (!include_char) {
                            break;
                        }
                    }
                    if (include_char) {
                        str_vecs.push_back(str.substr(i, j-i+1));
                    }
                }
            }
            sort(str_vecs.begin(), str_vecs.end(), [](string& str1, string& str2){
                return str1.length() < str2.length();
            });
            // sort(str_vecs.begin(), str_vecs.end(), comp1());
            return str_vecs[0];
        }
};

class Solution2 {
    public:
        static string shortest_substr(string& str, string& char_set) {
            vector<string> substr_vecs;
            for (int i = 0; i < str.length(); ++i) {
                for (int j = i; j < str.length(); ++j) {
                    bool exist_char;
                    for (auto ch:char_set) {
                        exist_char = false;
                        for (int k = i; k <= j; ++k) {
                            if (ch == str[k]) {
                                exist_char = true;
                                break;
                            }
                        }
                        if (!exist_char) {
                            break;
                        }
                    }
                    if (exist_char) {
                        substr_vecs.push_back(str.substr(i, j-i+1));
                    }
                }
            }
            sort(substr_vecs.begin(), substr_vecs.end(), [](string& a, string& b){
                return a.length() < b.length();
            });
            return substr_vecs[0];
        }
};

int main() {
    string str, char_set;
    cin >> str >> char_set;

    // cout << Solution1::shortest_substr(str, char_set);
    // cout << Solution2::shortest_substr(str, char_set);
    cout << Solution3::shortest_substr(str, char_set);
}